﻿        <!DOCTYPE html >
<html >
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
	学生信息管理平台
</title>
	<link href="../../Style/StudentStyle.css" rel="stylesheet" type="text/css" />
	<link href="../../Script/jBox/Skins/Blue/jbox.css" rel="stylesheet" type="text/css" />
	<link href="../../Style/ks.css" rel="stylesheet" type="text/css" />
	<link href="../../css/mine.css" type="text/css" rel="stylesheet">
    <script src="../../Script/jBox/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="../../Script/jBox/jquery.jBox-2.3.min.js" type="text/javascript"></script>
    <script src="../../Script/jBox/i18n/jquery.jBox-zh-CN.js" type="text/javascript"></script>
    <script src="../../Script/Common.js" type="text/javascript"></script>
    <script src="../../Script/Data.js" type="text/javascript"></script>

</head>
<body>

		<div class="div_head">
            <span>
                <span style="float:left">当前位置是：教务中心-》学生管理-》更新</span>
                <span style="float:right;margin-right: 8px;font-weight: bold"></span>
            </span>
        </div>
</div>
<div class="cztable">
    <form action="/Educational/student/studentServlet?method=updateInfo" method="post" id="myForm">
	<table border="1" width="100%" class="table_a">
        <input type="hidden" name="stuId" value=""/>
                <tr  width="120px;">
                    <td width="10%">学号：<span style="color:red">*</span>：</td>
                    <td>
						<input type="text" id="stuNo" name="stuNo" value="" />
                        <span id="mySpan"></span>
					</td>
                </tr>

                <tr  width="120px;">
                    <td>姓名<span style="color:red">*</span>：</td>
                    <td>
						<input type="text"  name="stuName" value="" />
					</td>
                </tr>
                 
                <tr>
                    <td>班级<span style="color:red">*</span>：</td>
                    <td id="selectId">
                        <select name="gid">
                            <option value="-1">请选择</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>性别<span style="color:red">*</span>：</td>
                    <td>
                        <input type="radio" id="boy" name="sex"  value="1" />男
                        <input type="radio" id="girl" name="sex"  value="0"/>女
                    </td>
                </tr>


				<tr>
                    <td>EMAIL：</td>
                    <td>
                        <input type="text" name="email" value="" />
                    </td>                
                </tr>

				<tr>
                    <td>联系电话：</td>
                    <td>
                        <input type="text" name="phone" value="" />
                    </td>
                </tr>

				<tr>
                    <td>户口所在地：</td>
                    <td>
                        <input type="text" name="registered" value=""  />
                    </td>                
                </tr>

				<tr>
                    <td>住址：</td>
                    <td>
                        <input type="text" name="address" value="" />
                    </td>                
                </tr>
				<tr>
                    <td>政治面貌：</td>
                    <td>
                        <input type="text" name="politics" value="" />
                    </td>                
                </tr>
				<tr>
                    <td>身份证号：</td>
                    <td>
                        <input type="text" name="idNumber" value="" />
                    </td>                
                </tr>
				
				<tr>
                    <td>专业：</td>
                    <td>
                        <input type="text" name="profession" value="" />
                    </td>                
                </tr>
					
				
				<tr>
                    <td>简介<span style="color:red">*</span>：</td>
                    <td>
                        <textarea name="introduction"></textarea>
                    </td>
                </tr>
				<tr>
					<td colspan=2 align="center">
						<input type="button" id="btnUpdate" value="保存">
					</td> 
				</tr>
			</table>
	</form>
</div>

            </div>
        </div>
    </div>
</body>
</html>
<script>
    $(function () {
       /* $("#stuNo").blur(function(){
            var val = $("#stuNo").val();
            $.get("/validateStuNo","stuNo="+val,function(text){
                $("#mySpan").html(text);
            });
        });*/
        $.ajax({
            type: "GET",
            url: "/grade/list",
            data: "",
            dataType: "json",
            success: function (vo) {
                let list = vo.list;
                let str = " <select  name=\"gid\">";
                for (let i = 0; i < list.length; i++) {
                    let gradeId=list[i].gradeId;
                    let gradeName=list[i].gradeName;
                    str+="<option value=\""+gradeId+"\">"+gradeName+"</option>"
                }
                str+="</select>";
                $("#selectId").html(str);
            }
        });
        let url = document.location.toString();//获取URL
        let stuId=url.GetValue("stuId");
        let pageNum=url.GetValue("pageNum");
        let pageSize=url.GetValue("pageSize");
        queryById(stuId);
        $("#btnUpdate").click(function () {
           // alert($("#myForm").serialize());
            $.ajax({
                type: "POST",//这里必须写POST.在后台会转成put类型的请求
                url: "/student/",
                data: $("#myForm").serialize()+"&_method=PUT",
                dataType:"json",
                success: function(vo){
                    if(vo.code==200) {
                        alert("更新成功！");
                        window.location.href = "/Educational/student/list.html?pageNum="+pageNum+"&pageSize="+pageSize;
                    }else{
                        alert(vo.msg);
                    }
                }
            });
        });

    });

    function queryById(stuId) {
        $.ajax({
            type: "GET",
            url: "/student/"+stuId, //RESTful风格的API定义
            data: "",
            success: function (vo) {
                let obj=vo.obj;
                let stuId=obj.stuId;
                let stuNo = obj.stuNo == null ? '' : obj.stuNo;
                let stuName = obj.stuName == null ? '' : obj.stuName;
                let gid = obj.gid;
                let sex = obj.sex;
                let email = obj.email == null ? '' : obj.email;
                let phone = obj.phone == null ? '' : obj.phone;
                let registered = obj.registered == null ? '' : obj.registered;
                let address = obj.address == null ? '' : obj.address;
                let politics = obj.politics == null ? '' : obj.politics;
                let idNumber = obj.idNumber == null ? '' : obj.idNumber;
                let profession = obj.profession == null ? '' : obj.profession;
                let introduction = obj.introduction == null ? '' : obj.introduction;
                $("input[name='stuId']").val(stuId);
                $("input[name='stuNo']").val(stuNo);
                $("input[name='stuName']").val(stuName);
                $("select[name='gid']").val(gid);
                if(sex==1){
                    $("input[id='boy']").attr("checked",true);
                }else {
                    $("input[id='girl']").attr("checked",true);
                }
                $("input[name='email']").val(email);
                $("input[name='phone']").val(phone);
                $("input[name='registered']").val(registered);
                $("input[name='address']").val(address);
                $("input[name='politics']").val(politics);
                $("input[name='idNumber']").val(idNumber);
                $("input[name='profession']").val(profession);
                $("textarea[name='introduction']").val(introduction);
            }
        });
    }

    String.prototype.GetValue= function(para) {
        let reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?")+1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }


</script>